package com.lagou.sessionshare.controller;

import com.lagou.sessionshare.service.LoginService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: jie.zhao
 * @create: 2021/03/29 11:06
 */
@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    @GetMapping("/user/login")
    public String login(String username, String pwd, HttpServletRequest request) {

        Long userId = loginService.login(username,pwd);
        if(userId==null){
            return "pwd error";
        }
        request.getSession().setAttribute("username",userId);
        return "login success";
    }

    @GetMapping("/user/auth")
    public String login(String username) {

        return "login";

    }


}
